package tv.huan.demo;

import androidx.multidex.MultiDexApplication;
import com.extscreen.runtime.EsKitInitHelper;
import com.sunrain.toolkit.utils.log.L;
import eskit.sdk.core.EsAppLifeCallback;
import eskit.sdk.core.EsKitInitCallback;
import eskit.sdk.core.EsManager;
import eskit.sdk.core.InitConfig;
import eskit.sdk.support.hebei.bilibili.module.EsBilibiliModule;

public class App extends MultiDexApplication implements EsKitInitCallback, EsAppLifeCallback {

    @Override
    public void onCreate() {
        super.onCreate();
        initEsSdk();
    }

    private void initEsSdk() {
        InitConfig config = InitConfig.getDefault()
                .setAppId("appid"/*BuildConfig.SDK_APP_ID*//*"425ba3c4033ecd9a"*/)
                .setChannel("channel"/*BuildConfig.CHANNEL*//*"DEV"*/)
                .setDebug(BuildConfig.DEBUG)
                .addFlags(InitConfig.FLAG_NOT_SUPPORT_WIDE_AREA_NETWORK)
//                .setCustomServer(BuildConfig.RUNTIME_API_URL)
//                .setCustomTrackServer(BuildConfig.RUNTIME_TRACK_URL)
//                .setBcCode(getBcCode())
////                .setProxyHostName("183.220.195.174").setProxyPort(8089)
                .setSdkInitCallback(this)
                .setAppLifeCallback(this);
//                .addApiProvider(new MyAPIProvider());

        EsKitInitHelper.init(this, config);
    }

    @Override
    public void onEsKitInitSuccess() {
        L.logD("初始化===>onEsKitInitSuccess===Success!");
        EsManager.get().registerModule(EsBilibiliModule.class.getName());
    }

    @Override
    public void onEsAppOpen(String pkg) {
        if (L.DEBUG) L.logD("onEsAppOpen: " + pkg);
    }

    @Override
    public void onEsAppClose(String pkg) {
        if (L.DEBUG) L.logD("onEsAppClose: " + pkg);
//        ThreadUtils.runOnUiThreadDelayed(this::checkKillSelf, 1000);
//        DlnaInitHelper.onEsAppClose();
    }

//    private void checkKillSelf() {
//        if (EsManager.get().isEsRunning()) return;
////        if (BuildConfig.AUTO_KILL) {
//            L.logIF("autoKillInBackground");
//            Process.killProcess(Process.myPid());
////        }
//    }

}
